<template>
  <div class="my-info-container">
    <div class="header">
      <h2>我的</h2>
    </div>
    
    <div class="info-content">
      <!-- 这里可以添加用户信息卡片 -->
      <div class="user-card">
        <div class="avatar">
          <!-- 用户头像 -->
          <img src="../assets/mmexport1740916330518.jpg" alt="用户头像">
        </div>
        <div class="user-info">
          <h3>用户名</h3>
          <p>用户ID: 123456</p>
        </div>
      </div>

      <!-- 功能列表 -->
      <div class="function-list">
        <div class="function-item">
          <i class="icon-settings"></i>
          <span>设置</span>
        </div>
        <div class="function-item">
          <i class="icon-history"></i>
          <span>历史记录</span>
        </div>
        <div class="function-item" @click="goToAbout">
          <i class="icon-about"></i>
          <span>关于我们</span>
        </div>
      </div>

      <!-- 添加退出登录按钮 -->
      <div class="logout-section">
        <van-button 
          type="danger" 
          block 
          @click="handleLogout"
          class="logout-btn"
        >
          退出登录
        </van-button>
      </div>
    </div>

 
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { showDialog } from 'vant'

const router = useRouter()

const handleLogout = () => {
  showDialog({
    title: '提示',
    message: '确定要退出登录吗？',
    showCancelButton: true,
  })
    .then(() => {
      // 用户点击确认
      // 1. 清除所有本地存储的数据
      localStorage.clear()
      // 2. 跳转到登录页
      router.replace('/login')
    })
    .catch(() => {
      // 用户点击取消
      // 不做任何操作
    })
}

const goToAbout = () => {
  router.push('/about')
}
</script>

<style scoped>
.my-info-container {
  min-height: 100vh;
  background-color: #f5f5f5;
  padding: 20px;
  position: relative;
}

.header {
  padding: 15px 0;
  text-align: center;
}

.header h2 {
  margin: 0;
  font-size: 18px;
  color: #333;
}

.info-content {
  margin-top: 20px;
}

.user-card {
  background: white;
  border-radius: 10px;
  padding: 20px;
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  overflow: hidden;
  margin-right: 15px;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-info h3 {
  margin: 0;
  font-size: 16px;
  color: #333;
}

.user-info p {
  margin: 5px 0 0;
  font-size: 14px;
  color: #666;
}

.function-list {
  background: white;
  border-radius: 10px;
  padding: 10px 0;
  margin-bottom: 20px; /* 添加底部间距 */
}

.function-item {
  padding: 15px 20px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
}

.function-item:last-child {
  border-bottom: none;
}

.function-item i {
  margin-right: 10px;
  font-size: 20px;
  color: #666;
}

.function-item span {
  font-size: 14px;
  color: #333;
}

/* 添加退出登录按钮样式 */
.logout-section {
  margin: 30px 0;
  padding: 0 20px;
}

.logout-btn {
  width: 100%;
  height: 44px;
  font-size: 16px;
  border-radius: 8px;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  background: white;
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -2px 6px rgba(0,0,0,0.1);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 0;
}

.nav-item i {
  font-size: 20px;
  color: #666;
  margin-bottom: 2px;
}

.nav-item span {
  font-size: 12px;
  color: #666;
}

.nav-item.active i,
.nav-item.active span {
  color: #4CAF50;
}
</style>